How do I rescue from a `require': no such file to load in ruby?

Posted by René Nyffenegger on Stack Overflow See other posts from Stack Overflow or by René Nyffenegger
Published on 2010-03-17T09:06:23Z Indexed on 2010/03/17 9:11 UTC
Read the original article Hit count: 142

Filed under:

I am trying to rescue from a `require': no such file to load in ruby in order to hint the user at specifying the -I flag in case he has forgotten to do so. Basically the code looks like:

begin
  require 'someFile.rb'
rescue
  puts "someFile.rb was not found, have you"
  puts "forgotten to specify the -I flag?"
  exit
end

I have expected the rescue part to take over execution in case someFile.rb was not found, but my assumption was wrong.

© Stack Overflow or respective owner

Related posts about ruby